#pragma once

#include "Protocol.hpp"
#include <iostream>

class Calculator
{
public:
    Calculator() {}
    ~Calculator() {}
    Responce Exec(Request &req)
    {
        Responce resp;
        // 分情况计算
        switch (req.Oper())
        {
            case '+':
                resp.SetResult(req.X() + req.Y());
                break;
            case '-':
                resp.SetResult(req.X() - req.Y());
                break;
            case '*':
                resp.SetResult(req.X() * req.Y());
                break;
            case '/':
            {
                if (req.Y() == 0)
                {
                    resp.SetCode(1);
                }
                else
                {
                    resp.SetResult(req.X() * req.Y());
                }
            }
            break;
            case '%':
            {
                if (req.Y() == 0)
                {
                    resp.SetCode(2);
                }
                else
                {
                    resp.SetResult(req.X() * req.Y());
                }
            }
            break;
            default:
                resp.SetCode(3);
                break;
        }
        return resp;
    }
    // 专门将Request -> 处理 ->Responce
};